package czk.databind;

import java.util.Map;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zkplus.databind.AnnotateDataBinderInit;

public class CZKDataBinderInit extends AnnotateDataBinderInit {

	protected String bean = null;

	@Override
	public void doInit(Page page, Map args) {
		super.doInit(page, args);
		this.bean = (String) args.get("bean");

	}

	@Override
	public void doAfterCompose(Page page, Component[] comps) throws Exception {
		super.doAfterCompose(page, comps);
		if (this.bean != null) {
			Class c = Class.forName(this.bean);
			Object beanObject = c.newInstance();
			this._binder.bindBean("bean", beanObject);
			// !!!
			comps[0].setAttribute("bean", beanObject);
			this._binder.loadAll();
		}
	}

}
